<!doctype html>
<html>
    <head>
        <title>安平县企业疫情防控信息大数据</title>
    
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
        <link rel="stylesheet" href="layui.css" media="all">
        <script src="layui.js"></script>
        <script src="jquery.1.12.4.js"></script>
        <link href="qiye.css" rel="stylesheet" />
        <style>
            #sfz_ol{
                display: flex;
                justify-content: left;
                margin-bottom: 15px;
            }
            #sfz_ol li {
                width: 100px;
                text-align: center;
                padding: 3px 0;
            }
            #sfz_ol li.ac{
                font-weight: bold;
                background-color: #009688;
                color: #fff;
            }
            #sfz_input input{
                display: none;
            }
            #sfz_input input.ac{
                display: block;
            }
            #zhuce{
                width: 100%;
                height: 42px;
                display: flex;
                justify-content: left;
                flex-wrap: wrap;
                box-shadow: 0 1px 5px #ccc;
                border: 1px solid #fff;
            }
        </style>
    </head>
    <body>
		<div id="black"></div>
		<div id="error">
            <div class="errorImg"><img src="error.png" width="180" height="140" /></div>
            <div class="errorTitle">失败，请选择人员入组！</div>
            <div class="errorBtn">
                <span onlick="Close()">点击关闭</span>
            </div>
		</div>
        <div class="layui-form layBox">
            <dl class="dl">
                <dt>企业名称：</dt>
                <dd>
                    <input id="name" value="" type="text" name="" lay-verify="title" autocomplete="off" placeholder="请输入企业名称" class="layui-input">
                </dd>
            </dl>
            <dl class="dl">
                <dt>统一社会信用代码</dt>
                <dd>
                    <input id="xinyong" value="" type="text" name="" lay-verify="title" autocomplete="off" placeholder="请输入统一社会信用代码" class="layui-input">
                </dd>
            </dl>
            <dl class="dl">
                <dt>企业法人：</dt>
                <dd>
                    <input id="user" value="" type="text" name="" lay-verify="title" autocomplete="off" placeholder="请输入企业法人" class="layui-input">
                </dd>
            </dl>
            
            <dl class="dl">
                <dt>法人身份证：</dt>
                <dd>
                    <ol id="sfz_ol">
                        <li class="ac">身份证</li>
                        <li>中国护照</li>
                    </ol>
                    <div id="sfz_input">
                        <input id="idCard" value="" type="text" name="" lay-verify="title" autocomplete="off" placeholder="请输入法人身份证号" class="layui-input ac">
                        <input id="passport" value="" type="text" name="" lay-verify="title" autocomplete="off" placeholder="请输入法人护照号" class="layui-input">
                    </div>
                    
                </dd>
            </dl>
            <dl class="dl">
                <dt>注册地：</dt>
                <dd>
                    <select id="zhuce" style="display: block;">
                        <option value="1">安平镇</option>
                        <option value="2">马店镇</option>
                        <option value="3">南王庄镇</option>
                        <option value="4">子文镇</option>
                        <option value="5">东黄城镇</option>
                        <option value="6">何庄乡</option>
                        <option value="7">油子乡</option>
                        <option value="8">两洼乡</option>
                        <option value="9">高新区</option>
                    </select>
                </dd>
            </dl>
            <dl class="dl">
                <dt>手机号：</dt>
                <dd>
                    <input id="phone" type="text" name="" lay-verify="title" autocomplete="off" placeholder="请输入手机号" class="layui-input" value="">
                </dd>
            </dl>
            
            <dl class="dl dl_yanzhengma">
                <dt>
                    <input id="yanzheng" type="text" name="" lay-verify="title" autocomplete="off" placeholder="请输入验证码" class="layui-input">
                </dt>
                <dd>
                    <div class="layui-btn" id="huoqu" _key="0">获取验证码</div>
                </dd>
            </dl>
            <div class="layui-btn onButton" _key="0">登记</div>
        </div>
        <div class="copy">
            <p><img src="http://qiye.city1000.cn/library/images/tishi.png" width="300" /></p>
            <p style="font-size: 18px;">安平县工业和信息化局</p>
            <p>技术支持：智慧安平</p>
        </div>

        <script>
            layui.use(['layer'], function(){
                var layer = layui.layer, //弹层
                form = layui.form;
            });

            var sfz_btn = $("#sfz_ol li");
            var sfz_input = $("#sfz_input input");
            sfz_btn.click(function(){
                var ts = $(this);
                var index = ts.index();
                ts.addClass("ac").siblings().removeClass("ac");
                sfz_input.eq(index).addClass("ac").siblings().removeClass("ac");
            })

            /*函数 start*/
            // 获取URL里的参数函数
            function getQueryString(name){
                var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
                var r = window.location.search.substr(1).match(reg);
                if(r!=null)return  unescape(r[2]); return null;
            }
            function Tanchuang (str, btnStr, num) {
                var black = $("#black");
                var box = $("#error");
                $(".errorTitle").html(str);
                if(num == 1){
                    // 关闭窗口
                    $(".errorBtn").html("<div class='baifenbai closeError'>"+btnStr+"</div>");
                    $(".closeError").click(function(){
                        var black = $("#black");
                        var box = $("#error");
                        black.fadeOut(500);
                        box.fadeOut(500);
                    });
                }
                if(num == 2){
                    // 跳转链接
                    $(".errorBtn").html("<div class='baifenbai linkUrl'>"+btnStr+"</div>");
                    $(".linkUrl").click(function(){
                        $(location).attr('href', 'http://qiye.city1000.cn/api/reg');
                    });
                }
                
                black.fadeIn(500);
                box.fadeIn(500);
            }
            /*函数 end*/
            var code = getQueryString("code");
            var state = getQueryString("state");
        
            if(code == "" || code == undefined || code == null){
                Tanchuang('网络繁忙', '点击重试', 2)
            }
        
            var url = "http://qiye.city1000.cn";
            
            var yzBtn = $("#huoqu");
        
            yzBtn.unbind('click');
            yzBtn.click(function(){
                
                var ts = $(this);
                var phone = $("#phone").val();
                var reg=/^1[3456789]\d{9}$/;
                if(!reg.test(phone)){
                    layer.msg('请输入正确的手机号',{icon:2});
                    return false;
                }
                var key = ts.attr("_key");
                if(key == 0){
                    ts.attr("_key", 1)
                    var djs = 60;
                    ts.html(djs);
                    ts.css({
                        'background': "#f1f1f1",
                        'color': "#000"
                    });
                    var timer = setInterval(function(){
                        djs--;
                        ts.html(djs);
                        if(djs == 0){
                            clearInterval(timer);
                            ts.attr("_key", 0);
                            ts.html("获取验证码");
                            ts.css({
                                "background": "#009688",
                                "color": "#fff"
                            });
                        }
                    }, 1000);
                    $.ajax({
                        url: url+"/api/duanxin",
                        type: "POST",
                        data:{
                            "phone": phone
                        },
                        dataType: "json",	//数据格式，如果后台输出为非json，则会报错，可不填
                        success: function(data){
                            console.log(data);
                        },
                        error:function(XMLHttpRequest,textStatus,errorThrown){
                            if(XMLHttpRequest.status!=200){
                                //状态码不为200，均为出错
                            };
                        }
                    });
                }
                
            });
        
            var btn = $(".onButton");
            btn.unbind('click');
            btn.click(function(){
                var ts = $(this);
                var name = $("#name").val();
                var xinyong = $("#xinyong").val();
                var user = $("#user").val();
                var idCard = "";
                var is_idCard = "";
                var phone = $("#phone").val();
                var yanzheng = $("#yanzheng").val();
                var cId = $("#zhuce").val();
        
                if(name.trim() == "" || xinyong.trim() == "" || user.trim() == "" || phone.trim() == "" || yanzheng.trim() == ""){
                    layer.msg("所有信息均不能为空", {icon: 2})
                    return false;
                }

                // 判断身份证或者护照是否为空以及取值
                var sfz_btn = $("#sfz_ol li");
                if(sfz_btn.eq(0).hasClass("ac") == true){
                    if($("#idCard").val() == ""){
                        layer.msg("身份证号不能为空", {icon: 2})
                        return false;
                    }else{
                        idCard = $("#idCard").val();
                        is_idCard = 1;
                        console.log("idCard:"+idCard+", is_idCard:"+is_idCard);
                    }
                }
                if(sfz_btn.eq(1).hasClass("ac") == true){
                    if($("#passport").val() == ""){
                        layer.msg("护照号不能为空", {icon: 2})
                        return false;
                    }else{
                        idCard = $("#passport").val();
                        is_idCard = 0;
                        console.log("idCard:"+idCard+", is_idCard:"+is_idCard);
                    }
                }

                var key = ts.attr("_key");
                if(key == 0){
                    ts.attr("_key", 1)
                    $.ajax({
                        url: url+"/api/reg/create",
                        type: "POST",
                        data:{
                            "name": name,
                            "xinyong": xinyong,
                            "user": user,
                            "idCard": idCard,
                            "phone": phone,
                            "yanzheng": yanzheng,
                            "code": code,
                            "is_idCard": is_idCard,
                            "cId": cId
                        },
                        dataType: "json",	//数据格式，如果后台输出为非json，则会报错，可不填
                        success: function(data){
                            console.log(data);
                            var code = data.code;
                            switch (code) {
                                case 112:
                                    layer.msg(data.msg,{icon:2});
                                    ts.attr("_key", 0);
                                    break;
                                case 1:
                                    layer.msg(data.msg,{icon:2});
                                    ts.attr("_key", 0);
                                    break;
                                case 2:
                                    layer.msg(data.msg,{icon:2});
                                    ts.attr("_key", 0);
                                    break;
                                case 3:
                                    layer.msg(data.msg,{icon:2});
                                    ts.attr("_key", 0);
                                    break;
                                case 4:
                                    layer.msg(data.msg,{icon:2});
                                    ts.attr("_key", 0);
                                    break;
                                case 5:
                                    layer.msg(data.msg,{icon:2});
                                    ts.attr("_key", 0);
                                    break;
                                case 6:
                                    layer.msg(data.msg,{icon:2});
                                    ts.attr("_key", 0);
                                    break;
                                case 110:
                                    layer.msg(data.msg,{icon:2});
                                    ts.attr("_key", 0);
                                    break;
                                case 111:
                                    layer.msg(data.msg,{icon:2});
                                    ts.attr("_key", 0);
                                    break;
                                case 404:
                                    layer.msg(data.msg,{icon:2});
                                    ts.attr("_key", 0);
                                    break;
                            }
                            if(data.code == 200){
                                layer.msg(data.msg);
                                setTimeout(function(){
                                    $(location).attr('href', "http://qiye.city1000.cn/api/content");
                                }, 1500);
                            }
                        },
                        error:function(XMLHttpRequest,textStatus,errorThrown){
                            ts.attr("_key", 0);
                            if(XMLHttpRequest.status!=200){
                                //状态码不为200，均为出错
                            };
                        }
                    });
                }
            });
        
           
        </script>
    </body>
</html>